[Unit]
Description=Send usb drive to sleep and switch off the usb port
#After=local-fs-pre.target ???

# retry ten times, then give up:
StartLimitBurst=10
StartLimitIntervalSec=111

[Service]
# this identifies a specific usb port, see "lsusb -t" and /sys/bus/usb/devices/. Required
Environment="node=X-X"
# this name does not reflect the above USB node at all, but it's the same device. Required.
Environment="hdparm_device=/dev/disk/by-id/asdasdXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# default value, optional
#Environment="restore_autosuspend=2000}"
# default value, optional
#Environment="restore_control=on}"

# On success, end service
Restart=on-failure
# take 10s between restarts, max. 10 restarts (see [Unit] section)
RestartSec=10

ExecStart=/full/path/to/hd-usb.sh off

[Install]
# System Initialization
WantedBy=sysinit.target
# Basic System
#WantedBy=basic.target
